import http from "./request";
import {IUser} from "./type"

// 请求验证码
export const getCaptcha = ()=>{
    return http({
        url:"/res/captcha",
        method:"get"
    })
}
// 验证用户是否存在
export const userIsExist = (loginId:string)=>{
    return http({
        url:`/api/user/userIsExist/${loginId}`,
        method:"get"
    })
}
// 用户注册
export const addUser = (data:IUser)=>{
    return http({
        url:"/api/user",
        method:"post",
        data
    })
}
// 用户登录
export const userLogin = (data:IUser)=>{
    return http({
        url:"/api/user/login",
        method:'post',
        data,
    })
}
// 根据id查找用户
export const getUserById = (id:string)=>{
    return http({
        url:`/api/user/${id}`,
        method:'get',
    })
}
// 恢复用户信息
export const whoami = ()=>{
    return http({
        url:"/api/user/whoami",
        method:'get'
    })
}
// 获取积分前十的用户
export const getTop = ()=>{
    return http({
        url:"/api/user/pointsrank",
        method:"get"
    })
}

// 根据id修改用户
export const updateUserById = (id:string,newUserInfo:Object)=>{
    return http({
        url:`/api/user/${id}`,
        method:"patch",
        data:newUserInfo
    })
}